package com.example.seabedmusic.entity;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

public class Song implements Parcelable {
    private String id;
    private String title;
    private String artist;
    private String cover;   // 封面URL
    private String url;     // 播放链接
    private String album;      // 专辑名
    private long duration;     // 时长（毫秒）
    private String lyrics;
    private boolean favorite = false;
    private boolean liked = false;
    private boolean isFavorite = false;
    private boolean isLiked = false;
    private boolean isLocal = false; // 是否为本地音乐
    private String filePath; // 本地文件路径

    // 默认构造函数
    public Song() {
    }

    // Parcelable实现
    protected Song(Parcel in) {
        id = in.readString();
        title = in.readString();
        artist = in.readString();
        cover = in.readString();
        url = in.readString();
        album = in.readString();
        duration = in.readLong();
        lyrics = in.readString();
        favorite = in.readByte() != 0;
        liked = in.readByte() != 0;
        isFavorite = in.readByte() != 0;
        isLiked = in.readByte() != 0;
        isLocal = in.readByte() != 0;
        filePath = in.readString();
    }

    public static final Creator<Song> CREATOR = new Creator<Song>() {
        @Override
        public Song createFromParcel(Parcel in) {
            return new Song(in);
        }

        @Override
        public Song[] newArray(int size) {
            return new Song[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeString(id);
        dest.writeString(title);
        dest.writeString(artist);
        dest.writeString(cover);
        dest.writeString(url);
        dest.writeString(album);
        dest.writeLong(duration);
        dest.writeString(lyrics);
        dest.writeByte((byte) (favorite ? 1 : 0));
        dest.writeByte((byte) (liked ? 1 : 0));
        dest.writeByte((byte) (isFavorite ? 1 : 0));
        dest.writeByte((byte) (isLiked ? 1 : 0));
        dest.writeByte((byte) (isLocal ? 1 : 0));
        dest.writeString(filePath);
    }

    // 其他构造函数
    public Song(String title, String artist) {
        this.title = title;
        this.artist = artist;
    }

    public Song(String id, String title, String artist, String cover, String url) {
        this.id = id;
        this.title = title;
        this.artist = artist;
        this.cover = cover;
        this.url = url;
    }

    // 新增带封面的构造函数
    public Song(String title, String artist, String cover) {
        this.title = title;
        this.artist = artist;
        this.cover = cover;
    }

    // 新增本地音乐构造函数
    public Song(String id, String title, String artist, String album, long duration, String filePath) {
        this.id = id;
        this.title = title;
        this.artist = artist;
        this.album = album;
        this.duration = duration;
        this.filePath = filePath;
        this.isLocal = true;
    }

    // Getter 和 Setter 方法
    public String getId() { return id; }
    public void setId(String id) { this.id = id; }

    public String getTitle() { return title; }
    public void setTitle(String title) { this.title = title; }

    public String getArtist() { return artist; }
    public void setArtist(String artist) { this.artist = artist; }

    public String getCover() { return cover; }
    public void setCover(String cover) { this.cover = cover; }

    public String getUrl() { return url; }
    public void setUrl(String url) { this.url = url; }

    public String getAlbum() { return album; }
    public void setAlbum(String album) { this.album = album; }

    public long getDuration() { return duration; }
    public void setDuration(long duration) { this.duration = duration; }

    public String getLyrics() { return lyrics; }
    public void setLyrics(String lyrics) { this.lyrics = lyrics; }

    public boolean isFavorite() {
        return favorite;
    }

    public void setFavorite(boolean favorite) {
        this.favorite = favorite;
    }

    public boolean isLiked() {
        return liked;
    }

    public void setLiked(boolean liked) {
        this.liked = liked;
    }

    public boolean getIsFavorite() {
        return isFavorite;
    }

    public void setIsFavorite(boolean isFavorite) {
        this.isFavorite = isFavorite;
    }

    public boolean getIsLiked() {
        return isLiked;
    }

    public void setIsLiked(boolean isLiked) {
        this.isLiked = isLiked;
    }

    public boolean isLocal() { return isLocal; }
    public void setLocal(boolean local) { isLocal = local; }

    public String getFilePath() { return filePath; }
    public void setFilePath(String filePath) { this.filePath = filePath; }

    @Override
    public String toString() {
        return "Song{" +
                "id='" + id + '\'' +
                ", title='" + title + '\'' +
                ", artist='" + artist + '\'' +
                ", album='" + album + '\'' +
                ", cover='" + cover + '\'' +
                ", url='" + url + '\'' +
                ", duration=" + duration +
                ", isLocal=" + isLocal +
                ", filePath='" + filePath + '\'' +
                '}';
    }
}